package contactbook.test.mock.dao;

import javax.persistence.EntityManager;

import contactbook.dao.GroupDAOInterface;
import contactbook.model.Group;

public class GroupDAOMock implements GroupDAOInterface {

	private Group group = null;
	
	@Override
	public Group addGroup(Group group) {
		this.group = new Group(group.getName(), group.getDescription());
		this.group.setId(1);
		this.group.setAccount(group.getAccount());
		this.group.setContacts(group.getContacts());
		return this.group;
	}

	@Override
	public void deleteGroup(int groupId) {
		if (group.getId() == groupId) 
			group = null;
	}

	@Override
	public boolean exists(int groupId) {
		return group.getId() != 0;
	}

	@Override
	public Group findById(int groupId) {
		return (group != null && group.getId() == groupId) ? group : null;
	}

	@Override
	public Group findByName(String name) {
		return (group != null && group.getName() == name) ? group : null;
	}

	@Override
	public void update(Group group) {
		this.group.setName(group.getName());
		this.group.setDescription(group.getDescription());
	}
	
	@Override
	public void setEntityManager(EntityManager em) {
		// Nothing
	}

}
